
import IElement from '../../interface/IElement';
import Controller from '../../Controller';
import React from 'react';
import { Object3D } from 'three';

/**
 * 选中的对象
 * @param controller 
 */
export default function useSelectedElement<O3D extends Object3D>(controller: Controller) {

    const selectedElementUuid = controller.useMemo(s => s.selectedElementUuid, []);

    const elementMap = controller.useMemo(s => s.elementMap, []);

    const element: IElement<O3D> | undefined = React.useMemo(() => selectedElementUuid ? elementMap.get(selectedElementUuid) : undefined, [elementMap, selectedElementUuid])

    return element;
}